-module(test_ssl_client).
-export([start/0, echo/1]).

-define(TCP_SEND_TIMEOUT, 15000).

%% Bugs: tls:send()不能正确返回, 问题处在driver中的SSL_write()方法中.
%%
start() ->
    tls:start().

echo(Data) -> 
    {ok, Socket} = gen_tcp:connect("localhost", 4567, [binary, {packet, 0},
                                                       {active, false},
				                       {reuseaddr, true},
				                       {nodelay, true},
				                       {send_timeout, ?TCP_SEND_TIMEOUT},
				                       {keepalive, true}]),
    {ok, TlsSocket} = tls:tcp_to_tls(Socket, [connect, {certfile, "./sslclient.pem"}]),
    R1 = tls:send(TlsSocket, Data),
    io:format("R1#~p~n",[R1]),
    case tls:recv(TlsSocket, 100) of
	{ok, Res} ->
	    io:format("(~p)received: ~p~n", [Socket, Res]);
	{error, closed} ->
	    io:format("(~p)tcp_closed~n", [Socket])
    end.
